﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Telerik.Windows.Controls.Charting;
using Telerik.Windows.Controls;
using System.Windows.Threading;

namespace DIST.LR.ZHJG.Controls.Chart
{
    public partial class ucMultiBar : UserControl
    {
        public ucMultiBar()
        {
            InitializeComponent();

            List<JyxydMultiBarData> data1 = new List<JyxydMultiBarData>();
            data1.Add(new JyxydMultiBarData(54500000, 82500000, "未处理"));
            data1.Add(new JyxydMultiBarData(27600000, 43400000, "整改中"));
            data1.Add(new JyxydMultiBarData(37100000, 60500000, "已超时"));
            data1.Add(new JyxydMultiBarData(37100000, 60500000, "已关闭"));
            data1.Add(new JyxydMultiBarData(37100000, 60500000, "总数"));

            MultiBarValue myvalue1 = new MultiBarValue();
            myvalue1.LableName = "成交出让面积";
            myvalue1.ValueName = "Cjcr";
            myvalue1.XCategoryName = "Gdfs";
            myvalue1.MultiBarGroupName = "bar1";
            myvalue1.Color = this.Resources["Barbrush_cj"] as SolidColorBrush;
            MultiBarValue myvalue2 = new MultiBarValue();
            myvalue2.LableName = "公告出让面积";
            myvalue2.ValueName = "Ggcr";
            myvalue2.XCategoryName = "Gdfs";
            myvalue2.MultiBarGroupName = "bar2";
            myvalue2.Color = this.Resources["Barbrush_gg"] as SolidColorBrush;
            List<MultiBarValue> myvalue = new List<MultiBarValue>();
            myvalue.Add(myvalue1);
            myvalue.Add(myvalue2);


            MultiBarInfo<JyxydMultiBarData> mydata = new MultiBarInfo<JyxydMultiBarData>();
            mydata.DataSource = data1;
            mydata.MultiBarValues = myvalue;

            Binding(mydata);//需要注释掉
        }

        public void Binding<T>(MultiBarInfo<T> info)
        {
            this.RadChart1.SeriesMappings.Clear();
            foreach (MultiBarValue multibar in info.MultiBarValues)
            {
                SeriesMapping mapping = new SeriesMapping();
                mapping.SeriesDefinition = new HorizontalBarSeriesDefinition()
                {
                    ShowItemToolTips = true,
                    StackGroupName = multibar.MultiBarGroupName,
                    ShowItemLabels = true,
                    LabelSettings = new BarLabelSettings()
                    {
                        Distance = 10,
                        LabelDisplayMode = Telerik.Windows.Controls.Charting.LabelDisplayMode.Outside,
                        ShowZeroValueLabels = false,
                        ShowConnectors = false
                    },
                };
                mapping.LegendLabel = multibar.LableName;
                mapping.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.YValue, FieldName = multibar.ValueName });
                mapping.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.XCategory, FieldName = multibar.XCategoryName });
                this.RadChart1.SeriesMappings.Add(mapping);
            }

            this.RadChart1.ItemsSource = info.DataSource;
        }
    }

    public class MultiBarInfo<T>
    {
        public MultiBarInfo()
        {
            this.MultiBarValues = new List<MultiBarValue>();
        }

        public List<MultiBarValue> MultiBarValues { get; set; }

        public List<T> DataSource { get; set; }
    }

    public class MultiBarValue
    {
        public string LableName { get; set; }
        public string ValueName { get; set; }
        public string XCategoryName { get; set; }
        public SolidColorBrush Color { get; set; }
        public string MultiBarGroupName { get; set; }
    }

    public class JyxydMultiBarData
    {
        private double _cjcr;
        private double _ggcr;
        private string _gdfs;

        public JyxydMultiBarData(double cjcr, double ggcr, string gdfs)
        {
            this._cjcr = cjcr;
            this._ggcr = ggcr;
            this._gdfs = gdfs;
        }

        public double Ggcr
        {
            get
            {
                return this._ggcr;
            }
            private set
            {
                this._ggcr = value;
            }
        }

        public double Cjcr
        {
            get
            {
                return this._cjcr;
            }
            private set
            {
                this._cjcr = value;
            }
        }

        public string Gdfs
        {
            get
            {
                return this._gdfs;
            }
            private set
            {
                this._gdfs = value;
            }
        }
    }
}
